import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_project/components/MTBody.dart';
import 'package:flutter_project/components/MTBottom.dart';
import 'package:flutter_project/components/MTTop.dart';

class MTMain extends StatefulWidget {
  const MTMain({Key? key}) : super(key: key);

  @override
  _MTMainState createState() => _MTMainState();
}

class _MTMainState extends State<MTMain> {
  List _foodList = [];
  @override
  void initState() {
    // TODO: implement initState
    getFoodData();
    super.initState();
  }

  getFoodData() async {
    Dio dio = Dio();
    var res = await dio
        .get('https://zhousg.atomgit.net/harmonyos-next/takeaway.json');
    setState(() {
      _foodList = res.data as List;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.bottomCenter,
      children: [
        Container(
          width: double.infinity,
          height: double.infinity,
          color: Colors.lightBlue,
          child: Column(
            children: [
              MTTop(),
              Expanded(child: MTBody(list: _foodList), flex: 1),
            ],
          ),
        ),
        const MTBottom(),
      ],
    );
  }
}
